<template>
  <el-dialog
      :lock-scroll="false"
      width="1300px"
      top="80px"
      custom-class="kinglex-dialog"
      :visible.sync="dialogVisible"
      @close="closeDialog"
      :title="dialogTitle"
  >
    <div>
      <el-table
          :data="tableData"
          style="width: 100%">
        <el-table-column
            prop="u_id"
            label="用户id"
        >
        </el-table-column>
        <el-table-column
            prop="temperature"
            label="当前体温"
        >
        </el-table-column>
        <el-table-column
            prop="hot"
            label="是否发热">
        </el-table-column>
        <el-table-column
            prop="leaveout"
            label="是否离开学校">
        </el-table-column>
        <el-table-column
            prop="hesuan"
            label="是否经过核酸检测"
            min-width="100">
        </el-table-column>
        <el-table-column
            prop="mask"
            label="口罩是否充足">
        </el-table-column>
        <el-table-column
            prop="masknum"
            label="口罩剩余数量">
        </el-table-column>
        <el-table-column
            prop="kills"
            label="杀毒用品是否充足"
            min-width="100">
        </el-table-column>
        <el-table-column
            prop="createtime"
            label="健康表创建时间"
            min-width="100">
        </el-table-column>
      </el-table>
    </div>
  </el-dialog>

</template>

<script>
export default {
  name: "studentInfo",
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    typeNum:{
      type:Number,
      required: true
    }
  },
  model: {
    prop: 'visible',
    event: 'changeVisible'
  },
  data(){
    return{
      dialogTitle:'',
      dialogVisible:false,
      tableData: []
    }
  },
  watch: {
    visible(val) {
      this.dialogVisible = val;
      //打开表单时候发送请求获取当天健康表信息
      if(val===true){
        this.$Axios ({
          url:"/students/gethealthNowDay",
          method:"get",
          data:{},
          success:(result)=> {
            //当健康表不为空时，将数据渲染到表格上
            if(result.length){
              result.forEach((item)=>{
                item.createtime = this.utc2beijing(item.createtime)
              })
              switch (this.typeNum){
                case 3:
                  this.tableData = [];
                  result.forEach((item)=>{
                    if(item.temperature<=35 || item.temperature>=38){
                      this.tableData.push(item)
                    }
                  })
                  break;
                case 4:
                  this.tableData = [];
                  result.forEach((item)=>{
                    if(item.gohubei==='是'){
                      this.tableData.push(item)
                    }
                  })
                  break;
                default:
                  this.tableData = result
              }
            }
          }
        });
      }
    },
    typeNum(val){
      if(val===1){
        this.dialogTitle='总检测人员信息'
      }else if (val===2){
        this.dialogTitle='所有学生填报信息'
      } else if (val===3){
        this.dialogTitle='今日高危人群信息'
      } else if (val===4){
        this.dialogTitle='今日经过高危地区人群信息'
      }
    }
  },
  methods:{
    closeDialog() {
      this.$emit('changeVisible', false);
    },
    utc2beijing(utc_datetime) {
// 转为正常的时间格式 年-月-日 时:分:秒
  var T_pos = utc_datetime.indexOf('T');
  var Z_pos = utc_datetime.indexOf('Z');
  var year_month_day = utc_datetime.substr(0,T_pos);
  var hour_minute_second = utc_datetime.substr(T_pos+1,Z_pos-T_pos-1);
  var new_datetime = year_month_day+" "+hour_minute_second; // 2017-03-31 08:02:06

// 处理成为时间戳
  timestamp = new Date(Date.parse(new_datetime));
  timestamp = timestamp.getTime();
  timestamp = timestamp/1000;

// 增加8个小时，北京时间比utc时间多八个时区
  var timestamp = timestamp+8*60*60;

// 时间戳转为时间
  var beijing_datetime = new Date(parseInt(timestamp) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
  return beijing_datetime; // 2017-03-31 16:02:06
}
  }
}
</script>

<style scoped>

</style>
